package com.wxl.common.util

import android.content.Context
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.interfaces.OnSrcViewUpdateListener
import com.lxj.xpopup.interfaces.XPopupImageLoader
import java.io.File

/**
 * create file time : 2021/3/15
 * create user : wxl
 * subscribe :
 */

class ImageViewer {

    companion object {
        fun showResources(
            srcView: ImageView,
            position: Int,
            datas: ArrayList<Any>,
            swp: OnSrcViewUpdateListener
        ) {
            if (srcView.context is AppCompatActivity) {
                XPopup.Builder(srcView.context).asImageViewer(srcView, position, datas,
                    false, false, -1, -1, -1, false,
                    swp
                    , object : XPopupImageLoader {
                        override fun loadImage(position: Int, uri: Any, imageView: ImageView) {
                            ImgLoader.loadResouce(imageView, uri as Int)
                        }

                        override fun getImageFile(context: Context, uri: Any): File? {
                            return FileCommon.getExternalImageFile()
                        }

                    }
                ).toggle()
            }
        }
    }
}